<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    x:Class="OpenLS.Chart.UI.BarChartResources"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:chartui="clr-namespace:OpenLS.Chart.UI"
  xmlns:chart="http://schemas.Kherty.com/office/2007/chart"
  xmlns:Internals="clr-namespace:OpenLS.Chart.UI.Internals">
  <ResourceDictionary.MergedDictionaries>
        <chartui:Axis2DResources/>
  </ResourceDictionary.MergedDictionaries>
    <DataTemplate DataType="{x:Type chart:BarChart}" x:Key="smallBarChart">
        <Grid>
            <ContentPresenter
                Name="minorGrid"
                chartui:AxisElement.Orientation="Vertical"
                chartui:AxisElement.Minimum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Minimum}"
                chartui:AxisElement.Maximum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Maximum}">
                <chartui:AxisElement.MinorStep>
                    <MultiBinding Converter="{x:Static Internals:ChartConverters.MinMaxToMinorStepConverter}">
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Minimum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Maximum)"/>
                    </MultiBinding>
                </chartui:AxisElement.MinorStep>
                <ContentPresenter.Content>
                    <MultiBinding Converter="{x:Static Internals:ChartConverters.MinMaxToMinorInfoConverter}">
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Minimum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Maximum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.MinorStep)"/>
                        <Binding Path="ValueAxis"/>
                        <Binding Path="ValueAxis.MinorGridLines"/>
                    </MultiBinding>
                </ContentPresenter.Content>
            </ContentPresenter>
            <ContentPresenter
                Name="majorGrid"
                chartui:AxisElement.Orientation="Vertical"
                chartui:AxisElement.Minimum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Minimum}"
                chartui:AxisElement.Maximum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Maximum}">
                <chartui:AxisElement.MajorStep>
                    <MultiBinding Converter="{x:Static Internals:ChartConverters.MinMaxToMajorStepConverter}">
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Minimum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Maximum)"/>
                    </MultiBinding>
                </chartui:AxisElement.MajorStep>
                <ContentPresenter.Content>
                    <MultiBinding Converter="{x:Static Internals:ChartConverters.MinMaxToMajorInfoConverter}">
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Minimum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.Maximum)"/>
                        <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:AxisElement.MajorStep)"/>
                        <Binding Path="ValueAxis"/>
                        <Binding Path="ValueAxis.MajorGridLines"/>
                    </MultiBinding>
                </ContentPresenter.Content>
            </ContentPresenter>
            <ItemsControl ItemsSource="{Binding Path=Series}" ToolTip="{x:Static Internals:UIStringTable.PlotArea}" chartui:ChartElement.Chart="{Binding}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
            
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding ="{Binding Direction}" Value="{x:Static chart:BarDirection.Bar}">
                <Setter TargetName="majorGrid" Property="chartui:AxisElement.Orientation" Value="Horizontal"/>
                <Setter TargetName="minorGrid" Property="chartui:AxisElement.Orientation" Value="Horizontal"/>
                <Setter TargetName="minorGrid" Property="chartui:AxisElement.Minimum" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.XAxisInfo).Minimum}"/>
                <Setter TargetName="majorGrid" Property="chartui:AxisElement.Minimum" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.XAxisInfo).Minimum}"/>
                <Setter TargetName="minorGrid" Property="chartui:AxisElement.Maximum" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.XAxisInfo).Maximum}"/>
                <Setter TargetName="majorGrid" Property="chartui:AxisElement.Maximum" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.XAxisInfo).Maximum}"/>
                <Setter Property="chartui:ChartElement.XAxisInfo">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.AxisInfoFactory}" >
                            <Binding Path="ValueAxis.Minimum"></Binding>
                            <Binding Path="ValueAxis.Maximum"></Binding>
                            <Binding Path="(chartui:ChartElement.Observer).ActualMinimum" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="(chartui:ChartElement.Observer).Maximum" RelativeSource="{RelativeSource Self}"/>

                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Setter Property="chartui:ChartElement.XAxisInfo">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.AxisInfoFactory}">
                            <Binding Path="ValueAxis.Minimum"/>
                            <Binding Path="ValueAxis.Maximum"/>
                            <Binding Path="(chartui:ChartElement.Observer).ActualMinimum" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="(chartui:ChartElement.Observer).Maximum" RelativeSource="{RelativeSource Self}"/>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </DataTrigger>

        </DataTemplate.Triggers>
    </DataTemplate>
    
    <DataTemplate DataType="{x:Type chart:BarChart}" >
        <Grid chartui:ChartElement.Chart="{Binding}"
              
              chartui:ChartElement.XAxisInfo="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.Observer).MaxIndex, Converter={x:Static Internals:ChartConverters.SimpleAxisInfoFactory}}"
              >
            <chartui:ChartElement.Observer>
                <MultiBinding Converter="{x:Static Internals:ChartConverters.SeriesObserverFactory}">
                    <Binding Path="Series"/>
                    <Binding Path="Grouping"/>
                </MultiBinding>
            </chartui:ChartElement.Observer>

            <chartui:ChartElement.YAxisInfo>
                <MultiBinding Converter="{x:Static Internals:ChartConverters.AxisInfoFactory}" >
                    <Binding Path="ValueAxis.Minimum"></Binding>
                    <Binding Path="ValueAxis.Maximum"></Binding>
                    <Binding Path="(chartui:ChartElement.Observer).ActualMinimum" RelativeSource="{RelativeSource Self}"/>
                    <Binding Path="(chartui:ChartElement.Observer).Maximum" RelativeSource="{RelativeSource Self}"/>
                </MultiBinding>
            </chartui:ChartElement.YAxisInfo>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height ="Auto"/>
            </Grid.RowDefinitions>
            <ContentPresenter Content="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.PlotArea)}"
                          ContentTemplate="{x:Static chartui:PlotAreaResources.PlotAreaBackgroundTemplate}"
                          Grid.Row="1" Grid.Column="1"/>

            <ContentPresenter Grid.Row="1" Grid.Column="0" Content="{Binding ValueAxis}"  Name="seriesAxis"
                            chartui:AxisElement.Orientation="Vertical"
                              
                              chartui:AxisElement.AxisInfo="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo)}"
                              chartui:AxisElement.Minimum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Minimum}"
  chartui:AxisElement.Maximum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Maximum}">
            </ContentPresenter>

            <Grid Grid.Row="2" Grid.Column="1" Name="categoryAxisHolder" chartui:AxisElement.ItemsSource="{Binding Categories.Values}">
                <ContentPresenter Name="categoryAxis"
                              Content="{Binding CategoryAxis}"
                                  chartui:AxisElement.Maximum="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.XAxisInfo).Maximum}"
                              chartui:AxisElement.Orientation="Horizontal"
                              />
            </Grid>
            <ContentPresenter Grid.Row="1" Grid.Column="1" ContentTemplate="{StaticResource smallBarChart}" Content="{Binding}">
            </ContentPresenter>
            
        </Grid>
        <DataTemplate.Triggers>
      <DataTrigger Binding ="{Binding Direction}" Value="{x:Static chart:BarDirection.Bar}">
                <Setter TargetName ="seriesAxis" Property="chartui:AxisElement.Orientation" Value="Horizontal"/>
                <Setter TargetName ="seriesAxis" Property="Grid.Row" Value="2"/>
                <Setter TargetName ="seriesAxis" Property="Grid.Column" Value="1"/>
                <Setter TargetName ="categoryAxis" Property="chartui:AxisElement.Orientation" Value="Vertical"/>
                <Setter TargetName ="categoryAxisHolder" Property="Grid.Row" Value="1"/>
                <Setter TargetName ="categoryAxisHolder" Property="Grid.Column" Value="0"/>
                <Setter Property="chartui:ChartElement.XAxisInfo" >
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.AxisInfoFactory}">
                            <Binding Path="ValueAxis.Minimum"/>
                            <Binding Path="ValueAxis.Maximum"/>
                            <Binding Path="(chartui:ChartElement.Observer).ActualMinimum" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="(chartui:ChartElement.Observer).Maximum" RelativeSource="{RelativeSource Self}"/>

                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Setter Property="chartui:ChartElement.XAxisInfo">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.AxisInfoFactory}">
                            <Binding Path="ValueAxis.Minimum"/>
                            <Binding Path="ValueAxis.Maximum"/>
                            <Binding Path="(chartui:ChartElement.Observer).Minimum" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="(chartui:ChartElement.Observer).Maximum" RelativeSource="{RelativeSource Self}"/>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                
                <Setter Property="chartui:ChartElement.YAxisInfo" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.Observer).MaxIndex, Converter={x:Static Internals:ChartConverters.SimpleAxisInfoFactory}}"/>
                    <Setter Property="chartui:AxisElement.Maximum" Value= "{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.YAxisInfo).Maximum}" />

            </DataTrigger>
    </DataTemplate.Triggers>

  </DataTemplate>

</ResourceDictionary>